package controllerLayer;

import java.util.List;

import modelLayer.Customer;
import modelLayer.PartSalesOrder;
import modelLayer.Product;
import modelLayer.Supplier;
import DBLayer.*;

public class ProductController {

	private IFDBProduct dbPr = new DBProduct();


	//	private List<Product> listProduct;


	public List<Product> getAllProducts(boolean retriveAssociation)
	{			
		return dbPr.getAllProducts(retriveAssociation);
	}

	public Product findProduct(String productID, boolean retriveAssociation)
	{
		return dbPr.findProduct(productID, retriveAssociation);
	}

	public Product createProduct(String name, double purchasePrice, double salesPrice,
			double rentPrice, String countryOfOrigin, int minStock,
			Supplier supplier, String type)
	{
		Product prObj = new Product();
		try{		
			prObj.setName(name);
			prObj.setPurchasePrice(purchasePrice);
			prObj.setSalesPrice(salesPrice);
			prObj.setRentPrice(rentPrice);
			prObj.setContryOfOrgin(countryOfOrigin);
			prObj.setMinStock(minStock);
			prObj.setSupplier(supplier);
			prObj.setType(type);
		}
		catch(Exception e)
		{
			p("create object Customer error: "+ e);
		}



		return prObj;
	}

	public int insertProduct(Product prObj, boolean retriveAssociation)
	{
		int nextCoID = -1;

		try {
			if(dbPr.insertProduct(prObj, retriveAssociation) == 1)
			{
				nextCoID = GetMax.getMaxId("select max(productID) from Product");


				prObj = dbPr.findProduct(String.valueOf(nextCoID), false);	
				p("SingleWhere");
				p("ProductObj: "+prObj);
				p("product id: "+prObj.getProductID());								
				p("");
			}


		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return nextCoID;
	}





	public void p(String e)
	{
		System.out.println(e);
	}




}
